package com.step.mesh;

public class Vertex {
	public final Coordinate position;
	public final Color color;
	public final Coordinate uv;
	public final Coordinate normal;
	/**
	 *  创建顶点对象
	 * @param position 位置坐标
	 * @param color 顶点颜色
	 * @param uv 纹理坐标
	 * @param normal 法线
	 */
	public Vertex(Coordinate position, Color color, Coordinate uv, Coordinate normal){
		if(position == null) {
			throw new RuntimeException("Vertex:顶点初始化失败，位置坐标对象不能为空");
		}
		
		if(normal != null && position.numbers() != normal.numbers()){
			throw new RuntimeException("Vertex:顶点位置坐标与法线坐标个数不相同，它们应该在同一坐标系！");
		}
		
		this.position = position;
		this.color = color;
		this.uv = uv;
		this.normal = normal;
	}

	public Vertex(Coordinate position, Color color, Coordinate uv) {
		this(position,color,uv,null);
	}

	public Vertex(Coordinate position, Color color) {
		this(position,color,null,null);
	}

	public Vertex(Coordinate position, Coordinate uv) {
		this(position,null,uv,null);
	}

	public Vertex(Coordinate position) {
		this(position,new Color(),null,null);
	}
	
	public Vertex(float x, float y, short r, short g, short b, short a, int u,	int v) {
		this.position = new Coordinate(x, y);
		this.color = new Color(r, g, b, a);
		this.uv = new Coordinate(u, v);
		this.normal = null;
	}
	
	public Vertex(float x, float y, float z, short r, short g, short b, short a, int u,	int v) {
		this.position = new Coordinate(x, y, z);
		this.color = new Color(r, g, b, a);
		this.uv = new Coordinate(u, v);
		this.normal = null;
	}

	/**
	 * 是否有颜色
	 * @return
	 */
	public boolean hasColor(){
		return color != null;
	}
	
	/**
	 * 是否有纹理坐标
	 * @return
	 */
	public boolean hasUV(){
		return uv !=null;
	}
	
	/**
	 * 是否有法线向量
	 * @return
	 */
	public boolean hasNormal(){
		return normal != null;
	}

	public Float[] toArray() {
		// TODO Auto-generated method stub
		return null;
	}
}
